<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="图片名称" prop="bannerName">
        <el-input
          v-model="queryParams.bannerName"
          placeholder="请输入图片名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别" prop="bannerType">
        <el-select
          v-model.number="queryParams.bannerType"
          placeholder="请选择类别"
        >
          <el-option label="用户端轮播图" :value="1"></el-option>
          <el-option label="采购端轮播图" :value="2"></el-option>
          <el-option label="logo" :value="3"></el-option>
          <el-option label="用户广告" :value="5"></el-option>
          <el-option label="采购广告" :value="6"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mall:banner:add']"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bannerList">
      <el-table-column label="ID" align="center" prop="id" />
      <!-- <el-table-column label="父级id" align="center" prop="pid" /> -->
      <el-table-column label="图片名称" align="center" prop="bannerName" />
      <el-table-column label="图片路径" align="center" prop="bannerPath">
        <template slot-scope="scope">
          <el-image
            :src="scope.row.bannerPath"
            fit="fill"
            class="img"
            :preview-src-list="[scope.row.bannerPath]"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column label="链接" align="center" prop="bannerUrl" />
      <el-table-column label="是否外链" align="center" prop="isSide">
        <template slot-scope="scope">
          <el-tag
            effect="dark"
            size="mini"
            type="success"
            v-if="scope.row.isSide === 1"
            >是</el-tag
          >
          <el-tag
            effect="dark"
            size="mini"
            type="danger"
            v-if="scope.row.isSide === 0"
            >否</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="类别" align="center" prop="bannerType">
        <template slot-scope="scope">
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 1"
            >用户端轮播图</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 2"
            >采购端轮播图</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 3"
            >logo</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 4"
            >用户广告</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 5"
            >采购广告</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 6"
            >首页条形广告图</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 7"
            >首页方形广告图</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 8"
            >优惠券落地页</el-tag
          >
          <el-tag effect="dark" size="mini" v-if="scope.row.bannerType == 9"
            >小程序首页轮播图</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="bannerSort">
        <template slot-scope="scope">
          {{ scope.row.bannerSort }}
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSort(scope.row)"
            v-hasPermi="['mall:banner:changeSort']"
          ></el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="开始时间"
        align="center"
        prop="startTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="结束时间"
        align="center"
        prop="endTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否上架" align="center" prop="isShelf">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isShelf"
            :active-value="1"
            :inactive-value="0"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mall:banner:edit']"
            >修改</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleGoods(scope.row)"
            v-hasPermi="['mall:banner:edit']"
            >关联商品</el-button
          > -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mall:banner:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 修改排序 -->
    <el-dialog title="修改排序" :visible.sync="isSort" width="400px">
      <el-form
        :model="sortForm"
        ref="sort"
        :rules="sortRule"
        label-width="80px"
      >
        <el-form-item label="排序" prop="bannerSort">
          <el-input
            v-model.number="sortForm.bannerSort"
            placeholder="请输入排序"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormSort">确 定</el-button>
        <el-button @click="isSort = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改商城首页轮播图对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <!-- <el-form-item label="父级id" prop="pid">
          <el-input v-model="form.pid" placeholder="请输入父级id" />
        </el-form-item> -->
        <el-row :gutter="20">
          <el-col :span="13">
            <el-form-item label="图片名称" prop="bannerName">
              <el-input
                v-model="form.bannerName"
                placeholder="请输入图片名称"
              />
            </el-form-item>
            <el-form-item label="是否外链" prop="isSide">
              <!-- <el-input v-model="form.isSide" placeholder="请输入是否外链" /> -->
              <el-radio-group v-model.number="form.isSide">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="链接" prop="bannerUrl" v-if="form.isSide == 1">
              <el-input v-model="form.bannerUrl" placeholder="请输入链接" />
            </el-form-item>

            <el-form-item label="是否上架" prop="isShelf">
              <el-radio-group v-model.number="form.isShelf">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="商城类型" prop="isXcx">
              <el-radio-group v-model.number="form.isXcx">
                <el-radio :label="1">H5</el-radio>
                <el-radio :label="2">小程序</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="搜索类别" prop="typeId">
              <!-- <el-input v-model="form.isSide" placeholder="请输入是否外链" /> -->
              <el-radio-group
                v-model.number="form.typeId"
                @input="handleTypeChange"
              >
                <el-radio :label="1">分类</el-radio>
                <el-radio :label="2">应用场景</el-radio>
                <el-radio :label="3">品牌</el-radio>
                <el-radio :label="4">商品</el-radio>
                <el-radio :label="5">渠道</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="分类" prop="cateId" v-if="form.typeId == 1">
              <treeselect
                v-model="form.cateId"
                :options="deptOptions"
                :normalizer="normalizer"
                :show-count="true"
                @select="handleChangeTree"
                placeholder="请选择分类"
              />
            </el-form-item>
            <el-form-item label="应用场景" prop="tagId" v-if="form.typeId == 2">
              <el-select
                v-model.number="form.tagId"
                placeholder="请选择应用场景"
                @change="onsceneOptions($event)"
              >
                <el-option
                  v-for="item in sceneOptions"
                  :key="item.goodsTagId"
                  :label="item.goodsTag"
                  :value="item.goodsTagId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="品牌" prop="brandId" v-if="form.typeId == 3">
              <el-select
                v-model.number="form.brandId"
                filterable
                placeholder="请选择品牌"
                @change="onbrandOptions($event)"
              >
                <el-option
                  v-for="item in brandOptions"
                  :key="item.id"
                  :label="item.brandName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="商品"
              prop="goodsId"
              style="width: 100%"
              v-if="form.typeId == 4"
            >
              <el-select
                style="width: 100%"
                v-model.number="form.goodsId"
                filterable
                placeholder="请选择商品"
                @change="onproductOptions($event)"
              >
                <el-option
                  style="width: 100%"
                  v-for="item in productOptions"
                  :key="item.mallProductId"
                  :label="item.productName"
                  :value="item.mallProductId"
                ></el-option>
                <!-- <el-option
                  v-for="item in productOptions"
                  :key="item.mallProductId"
                  :label="item.productName"
                  :value="item.mallProductId"
                ></el-option> -->
              </el-select>
            </el-form-item>
            <!-- 选择渠道 -->
            <el-form-item label="选择渠道" v-if="form.typeId == 5">
              <el-select v-model="form.chooseId" placeholder="请选择渠道">
                <el-option
                  v-for="item in channelList"
                  :key="item.id"
                  :label="item.channelName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="类别" prop="bannerType">
              <el-select
                v-model.number="form.bannerType"
                placeholder="请选择类别"
              >
                <el-option label="用户端轮播图" :value="1"></el-option>
                <el-option label="采购端轮播图" :value="2"></el-option>
                <el-option label="logo" :value="3"></el-option>
                <el-option label="用户广告" :value="4"></el-option>
                <el-option label="采购广告" :value="5"></el-option>
                <el-option label="首页条形广告图" :value="6"></el-option>
                <el-option label="首页方形广告图" :value="7"></el-option>
                <el-option label="优惠券落地页" :value="8"></el-option>
                <el-option label="小程序首页轮播图" :value="9"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="排序" prop="bannerSort">
              <el-tooltip
                class="item"
                effect="dark"
                content="排序值从0开始，值越小排序越靠前"
                placement="top-start"
              >
                <el-input
                  v-model.number="form.bannerSort"
                  onkeyup="value=value.replace(/[^\d]/g,'')"
                  placeholder="请输入排序"
                />
              </el-tooltip>
            </el-form-item>
            <!-- <el-form-item label="等级" prop="showLevel">
              <el-input
                v-model.number="form.showLevel"
                placeholder="请输入等级"
              />
            </el-form-item> -->
            <el-form-item label="开始时间" prop="startTime">
              <el-date-picker
                clearable
                :editable="false"
                v-model="form.startTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择开始时间"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间" prop="endTime">
              <el-date-picker
                clearable
                :editable="false"
                v-model="form.endTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择结束时间"
              >
              </el-date-picker>
            </el-form-item>
            <!-- 轮播图位置 -->
            <el-form-item label="轮播图位置" prop="carouselPositionId">
              <el-select
                v-model="form.carouselPositionId"
                placeholder="请选择轮播图位置"
              >
                <el-option
                  v-for="item in positionList"
                  :key="item.id"
                  :label="item.positionKey"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <!-- 类型 -->
            <el-form-item label="类型" prop="type">
              <el-radio-group
                v-model.number="form.type"
                @change="handleTypesSelect"
              >
                <el-radio :label="1">渠道</el-radio>
                <el-radio :label="2">品牌</el-radio>
                <el-radio :label="3">分类</el-radio>
              </el-radio-group>
            </el-form-item>
            <!-- 选择渠道 -->
            <el-form-item label="选择渠道" v-if="form.type == 1">
              <el-select v-model="form.linkId" placeholder="请选择渠道">
                <el-option
                  v-for="item in channelList"
                  :key="item.id"
                  :label="item.channelName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <!-- 选择品牌 -->
            <el-form-item label="选择品牌" v-if="form.type == 2">
              <el-select v-model="form.linkId" placeholder="请选择品牌">
                <el-option
                  v-for="item in brandOptions"
                  :key="item.id"
                  :label="item.brandName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <!-- 选择分类 -->
            <el-form-item label="选择分类" v-if="form.type == 3">
              <treeselect
                v-model="form.linkId"
                :options="deptOptions"
                :normalizer="normalizer"
                :show-count="true"
                @select="handleChangeTree"
                placeholder="请选择分类"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="商品图片" prop="expOne">
          <!-- <el-upload
            class="upload-demo"
            ref="xlsUpload"
            action=""
            :show-file-list="false"
            :file-list="fileList"
            :http-request="handleFileUpload"
          >
            <img v-if="form.bannerPath" :src="form.bannerPath" class="avatar" />

            <i class="el-icon-plus avatar-uploader-icon" v-else></i>
          </el-upload> -->
          <ImageUpload v-model="form.bannerPath" @input="handleUploadUrl" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 关联商品 -->
    <related-goods
      :openGoods.sync="openGoods"
      @close="closeGoods"
      @getGoodsList="getGoods"
      :selectedProductList.sync="selectedProductList"
    ></related-goods>
  </div>
</template>

<script>
import {
  listBanner,
  getBanner,
  delBanner,
  addBanner,
  updateBanner,
  showBankBannerProduct,
  saveCarousel,
  changeUpdateIsShelf,
  changeSort,
  showProductCategory,
  tagList,
  brandListNew,
  showMallAllProduct,
} from "@/api/system/banner";
import { allPositionList } from "@/api/mallGuan/bannerPosition";
import RelatedGoods from "../../components/relatedGoods.vue";
import { uploadimage } from "@/api/system/lunbo";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { allChannelList } from "@/api/mallGuan/channel";
import ImageUpload from "@/components/ImageUpload";
export default {
  name: "Banner",
  components: {
    RelatedGoods,
    Treeselect,
    ImageUpload,
  },
  data() {
    return {
      openGoods: false,

      selectedProductList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      fileList: [],
      // 总条数
      total: 0,
      // 商城首页轮播图表格数据
      bannerList: [],
      // 轮播图位置列表
      positionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示修改排序弹出层
      isSort: false,
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "title",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bannerName: null,
      },
      //应用场景列表
      sceneOptions: [],
      //品牌列表
      brandOptions: [],
      //渠道列表
      channelList: [],
      //商品列表
      productOptions: [],
      // 表单参数
      form: {
        bannerName: null,
        bannerPath: null,
        bannerUrl: null,
        isShelf: null,
        isSide: null,
        isXcx: null,
        bannerType: null,
        bannerSort: null,
        startTime: null,
        endTime: null,
        showLevel: null,
        createTime: null,
      },
      //修改排序
      sortForm: {
        bannerSort: null,
      },
      //排序校验
      sortRule: {
        bannerSort: [
          {
            required: true,
            message: "请输入排序",
            trriger: "blur",
            type: "number",
          },
        ],
      },
      // 表单校验
      rules: {
        bannerName: [
          { required: true, message: "请输入图片名称", trriger: "blur" },
        ],
        bannerSort: [
          {
            required: true,
            message: "请输入排序",
            trriger: "blur",
            type: "number",
          },
        ],
        bannerPath: [
          { required: true, message: "请输入图片路径", trriger: "blur" },
        ],
        showLevel: [
          {
            required: true,
            message: "请输入等级",
            trriger: "blur",
            type: "number",
          },
        ],

        isSide: [
          {
            required: true,
            message: "请选择是否外链",
            trriger: "click",
            type: "number",
          },
        ],
        startTime: [
          { required: true, message: "请选择开始时间", trriger: "change" },
        ],
        endTime: [
          { required: true, message: "请选择结束时间", trriger: "change" },
        ],
        isShelf: [
          {
            required: true,
            message: "请选择是否上架",
            trriger: "click",
            type: "number",
          },
        ],
        bannerType: [
          {
            required: true,
            message: "请选择类别",
            trriger: "change",
            type: "number",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getDeptTree();
    this.getPositionList();
    this.getChannelList();
  },
  methods: {
    //获取渠道列表
    getChannelList() {
      allChannelList().then((response) => {
        this.channelList = response.data;
      });
    },
    //监听类型
    handleTypesSelect() {
      this.form.linkId = null;
      console.log(this.form.linkId);
    },
    //获取轮播图位置列表
    getPositionList() {
      allPositionList().then((response) => {
        this.positionList = response.data;
      });
    },
    //切换类别重置之前的选择
    handleTypeChange() {
      this.form = {
        ...this.form,
        tagId: null,
        brandId: null,
        cateId: null,
        level: null,
      };
    },
    //获取应用场景列表
    getSceneList() {
      tagList().then((response) => {
        this.sceneOptions = response.data;
      });
    },
    //选择应用场景列表
    onsceneOptions(id) {
      let dir = this.sceneOptions.find((item) => item.goodsTagId === id);
      this.form.title = dir.goodsTag;
    },
    //获取商品列表
    getGoodsList() {
      showMallAllProduct().then((res) => {
        this.productOptions = res.data;
      });
    },
    //选择商品列表
    onproductOptions(id) {
      let dir = this.productOptions.find((item) => item.mallProductId === id);
      this.form.title = dir.productName;
    },
    //获取品牌列表
    getBrandList() {
      brandListNew().then((response) => {
        this.brandOptions = response.data;
      });
    },
    //选择品牌列表
    onbrandOptions(id) {
      let dir = this.brandOptions.find((item) => item.id === id);
      this.form.title = dir.brandName;
    },
    // 切换分类
    handleChangeTree(node) {
      console.log(node);
      this.form.level = node.level;
      this.form.searchName = node.title;
      this.form.title = node.title;
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      showProductCategory().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 筛选节点
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.title,
        level: node.level,
        children: node.children,
      };
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },
    // 打开关联商品
    handleGoods(row) {
      this.carouselSeriesId = row.id;
      this.getSelectGoods();
      this.openGoods = true;
    },
    //关闭商品列表
    closeGoods(e) {
      this.openGoods = false;
    },
    //提交关联商品
    getGoods(e) {
      console.log(e);
      const data = {
        carouselSeriesId: this.carouselSeriesId,
      };
      data.productIds = e.goodsIdArs.map((v) => v.productId);
      saveCarousel(data).then((res) => {
        this.$message({
          message: res.msg,
          type: "success",
        });
        this.openGoods = false;
      });
    },
    getSelectGoods() {
      showBankBannerProduct({ carouselSeriesId: this.carouselSeriesId }).then(
        (res) => {
          this.selectedProductList = res.data;
        }
      );
    },
    /** 查询商城首页轮播图列表 */
    getList() {
      this.loading = true;
      listBanner(this.queryParams).then((response) => {
        this.bannerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //修改排序
    handleSort(row) {
      this.isSort = true;
      this.sortForm = {
        bannerSort: row.bannerSort,
        id: row.id,
      };
    },
    //修改排序提交
    submitFormSort() {
      this.$refs["sort"].validate((valid) => {
        if (valid) {
          changeSort(this.sortForm).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.isSort = false;
            this.getList();
          });
        }
      });
    },
    handleUploadUrl(url) {
      this.form.bannerPath = url;
    },
    handleFileUpload({ file }) {
      let fd = new FormData();
      fd.append("file", file);
      uploadimage(fd).then((v) => {
        // Base64.decode("写在这里") 这是解码的后端给的base64用这个方法解码
        // Base64.decode(console.log(msg));
        if (v.code == 200) {
          console.log(v);
          let arr = v.data.url;
          this.form.bannerPath = arr;
          console.log(this.form.bannerPath);
          this.$modal.msgSuccess("上传成功");
        }
      });
    },
    // 商家状态修改
    handleStatusChange(row) {
      console.log(row);
      const { id, isShelf } = row;
      let text = row.isShelf == 1 ? "上架" : "下架";
      this.$modal
        .confirm("确认要" + text + "" + row.bannerName + "吗？")
        .then(function () {
          return changeUpdateIsShelf({ id, isShelf });
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.isShelf = row.isShelf == 1 ? 0 : 1;
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pid: null,
        bannerName: null,
        bannerPath: null,
        bannerUrl: null,
        isShelf: 1,
        isSide: 1,
        isXcx: null,
        bannerType: null,
        bannerSort: null,
        startTime: null,
        endTime: null,
        showLevel: null,
        createTime: null,
        type: 1,
        typeId: 1,
        linkId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商城首页轮播图";
      // this.form.isXcx = 1;
      this.$set(this.form, "isXcx", 1);
      this.getSceneList();
      this.getBrandList();
      this.getGoodsList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBanner(id).then((response) => {
        this.getSceneList();
        this.getBrandList();
        this.getGoodsList();
        this.form = response.data;
        if (this.form.typeId == 1) {
          //分类
          this.form.cateId = response.data.chooseId;
          this.form.tagId = null;
          this.form.brandId = null;
          this.form.goodsId = null;
        } else if (this.form.typeId == 2) {
          //场景
          this.form.cateId = null;
          this.form.tagId = response.data.chooseId;
          this.form.brandId = null;
          this.form.goodsId = null;
        } else if (this.form.typeId == 3) {
          //品牌
          this.form.cateId = null;
          this.form.tagId = null;
          this.form.brandId = response.data.chooseId;
          this.form.goodsId = null;
        } else if (this.form.typeId == 4) {
          //商品
          this.form.cateId = null;
          this.form.tagId = null;
          this.form.brandId = null;
          this.form.goodsId = response.data.chooseId;
        }
        console.log(this.form);
        this.open = true;
        this.title = "修改商城首页轮播图";
      });
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form);
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBanner(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBanner(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除商城首页轮播图编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBanner(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "banner/export",
        {
          ...this.queryParams,
        },
        `banner_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="less">
.el-radio {
  margin-right: 20px;
}
.img {
  width: 80px;
}
.avatar-uploader .avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.avatar-uploader .el-upload {
  border: 1px dashed #ccc;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  border: 1px dashed #ccc;
  width: 148px;
  height: 148px;
  line-height: 148px;
  text-align: center;
}
.avatar {
  width: 148px;
  height: 148px;
  display: block;
}
.image {
  width: 60px;
}
.image {
}
</style>
